REM @ECHO OFF
IF NOT "%1%"=="" GOTO START_TEST
ECHO USAGE: %0% zip_file_name
GOTO END
@ECHO ON

SET MSBUILD_MULTIPROCESS=/m
IF "%2%"=="" GOTO END_SETTING_COMPILE_PROCESS_COUNT
SET COMPILE_PROCESS_COUNT=%2%
SET MSBUILD_MULTIPROCESS=/m:%2%

:END_SETTING_COMPILE_PROCESS_COUNT

:START_TEST
SET SCRIPT_PATH=%~dp0

SET PROGRAMFILES_DIR_X86=%programfiles(x86)%
if NOT EXIST "%PROGRAMFILES_DIR_X86%" SET PROGRAMFILES_DIR_X86=%programfiles%
SET PROGRAMFILES_DIR=%programfiles%

REM Find Visual Studio or Msbuild
SET VS2005="%VS80COMNTOOLS%..\IDE\devenv.com"
SET VS2008="%VS90COMNTOOLS%..\IDE\devenv.com"
SET VS2010="%VS100COMNTOOLS%..\IDE\devenv.com"
SET VS2012="%VS110COMNTOOLS%..\IDE\devenv.com"
SET VS2013="%VS120COMNTOOLS%..\IDE\devenv.com"
SET VS2015="%VS140COMNTOOLS%..\IDE\devenv.com"

SET VS2017_DIR=%PROGRAMFILES_DIR_X86%\Microsoft Visual Studio\2017\Community
IF EXIST "%PROGRAMFILES_DIR_X86%\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.com" SET VS2017_DIR=%PROGRAMFILES_DIR_X86%\Microsoft Visual Studio\2017\Professional
IF EXIST "%PROGRAMFILES_DIR_X86%\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\devenv.com" SET VS2017_DIR=%PROGRAMFILES_DIR_X86%\Microsoft Visual Studio\2017\Enterprise
IF EXIST "%VS2017INSTALLDIR%\Common7\IDE\devenv.com" SET VS2017_DIR=%VS2017INSTALLDIR%
IF EXIST "%VS150COMNTOOLS%..\IDE\devenv.com" SET VS2017_DIR =%VS150COMNTOOLS%..\..
SET VS2017="%VS2017_DIR%\Common7\IDE\devenv.com" 


IF EXIST "%windir%\Microsoft.NET\Framework\v3.5\MSBuild.exe" SET MSBUILD35=%windir%\Microsoft.NET\Framework\v3.5\MSBuild.exe
IF EXIST "%windir%\Microsoft.NET\Framework64\v3.5\MSBuild.exe" SET MSBUILD35=%windir%\Microsoft.NET\Framework64\v3.5\MSBuild.exe
IF EXIST "%windir%\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe" SET MSBUILD40=%windir%\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe
IF EXIST "%PROGRAMFILES_DIR_X86%\MSBuild\14.0\bin\MSBuild.exe" SET MSBUILD140=%PROGRAMFILES_DIR_X86%\MSBuild\14.0\bin\MSBuild.exe
IF EXIST "%VS2017_DIR%\MSBuild\15.0\Bin\MSBuild.exe" SET MSBUILD150=%VS2017_DIR%\MSBuild\15.0\Bin\MSBuild.exe


SET SOLUTION=Emgu.CV.Android.Example.sln

IF EXIST "%MSBUILD35%" SET DEVENV="%MSBUILD35%"
IF EXIST "%MSBUILD40%" SET DEVENV="%MSBUILD40%"
IF EXIST "%MSBUILD140%" SET DEVENV="%MSBUILD140%"
IF EXIST "%MSBUILD150%" SET DEVENV="%MSBUILD150%"

REM if compile process count is set we cannot use devenv
IF NOT ("%COMPILE_PROCESS_COUNT%" == "") GOTO SET_BUILD_TYPE

IF EXIST %VS2005% SET DEVENV=%VS2005% 
IF EXIST %VS2008% SET DEVENV=%VS2008%
IF EXIST %VS2010% SET DEVENV=%VS2010%
IF EXIST %VS2012% SET DEVENV=%VS2012%
IF EXIST %VS2013% SET DEVENV=%VS2013%
IF EXIST %VS2015% SET DEVENV=%VS2015%
IF EXIST %VS2017% SET DEVENV=%VS2017%
REM IF "%2%"=="gpu" GOTO SET_BUILD_TYPE

:SET_BUILD_TYPE
IF %DEVENV%=="%MSBUILD35%" SET BUILD_TYPE=/property:Configuration=Release %MSBUILD_MULTIPROCESS% 
IF %DEVENV%=="%MSBUILD40%" SET BUILD_TYPE=/property:Configuration=Release %MSBUILD_MULTIPROCESS% 
IF %DEVENV%=="%MSBUILD140%" SET BUILD_TYPE=/property:Configuration=Release %MSBUILD_MULTIPROCESS% 
IF %DEVENV%=="%MSBUILD150%" SET BUILD_TYPE=/property:Configuration=Release %MSBUILD_MULTIPROCESS% 
IF %DEVENV%==%VS2005% SET BUILD_TYPE=/Build "Release|Any CPU"
IF %DEVENV%==%VS2008% SET BUILD_TYPE=/Build "Release|Any CPU" 
IF %DEVENV%==%VS2010% SET BUILD_TYPE=/Build "Release|Any CPU" 
IF %DEVENV%==%VS2012% SET BUILD_TYPE=/Build "Release|Any CPU" 
IF %DEVENV%==%VS2013% SET BUILD_TYPE=/Build "Release|Any CPU" 
IF %DEVENV%==%VS2015% SET BUILD_TYPE=/Build "Release|Any CPU" 
IF %DEVENV%==%VS2017% SET BUILD_TYPE=/Build "Release|Any CPU" 

IF EXIST tmp rm -rf tmp
mkdir tmp
SET ZIP_FILE_NAME=%1%
cp %ZIP_FILE_NAME% tmp/
cd tmp
unzip %ZIP_FILE_NAME%
cd libemgucv-android\Solution\Android
%SCRIPT_PATH%..\..\..\miscellaneous\nuget.exe restore %SOLUTION%
call %DEVENV% %BUILD_TYPE% %SOLUTION%
cd ..\..\..\..

:END